
<!--_meta 作为公共模版分离出去-->
{include file="public/_meta"}

<nav class="breadcrumb"> <a href="javascript:void(0);">首页</a>
        <span class="c-gray en">&gt;</span>
        <a href="javascript:void(0);">任务管理</a>
        <span class="c-gray en">&gt;</span>
        <a href="javascript:void(0);">任务列表</a>
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <div class="page-container">
        <div class="cl pd-20">
            <div class="text-c">
                <form action="" method="get" class="form form-horizontal" id="form-article-add" enctype="multipart/form-data">
                    <input type="text" class="input-text" style="width:250px" placeholder="请输入任务名称" name="keywords">
                    <button type="submit" class="btn btn-success"  name="">搜索任务</button>
                </form>
            </div>
            <div class="cl pd-5 bg-1 bk-gray mt-20">
                <a href="javascript:void(0);" onclick="add_task('新增任务','{:url(\'task/add_task\')}','950','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 新增任务</a>
                <a href="javascript:;" onclick="dataDel()" class="btn btn-danger radius">
                    <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
                </a>
                <span class="r">共有数据：<strong>{$count}</strong> 条</span>
            </div>
            <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-sort">
                <thead>
                <tr>
                    <th scope="col" colspan="13">任务列表</th>
                </tr>
                <tr class="text-c">
                    <th><input type="checkbox" name="" value=""></th>
                    <th>ID</th>
                    <th>排序</th>
                    <th>任务名称</th>
                    <th>任务地址</th>
                    <th>请求时间</th>
                    <th>完成时间</th>
                    <th>完成状态</th>
                    <th>完成次数</th>
                    <th>任务描述</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="list" id="vo"}
                    <tr class="text-c api">
                        <td><input type="checkbox" value="{$vo.id}" name="id[]"></td>
                        <td>{$vo.id}</td>
                        <td width="50" class="sort">
                            <input class="input-text text-c" alt="{$vo.id}" onchange="task_sort(this)" type="number" value="{$vo.sort}" name="sort">
                        </td>
                        <td>{$vo.task_name}</td>
                        <td>{$vo.task_url}</td>
                        <td>{$vo.task_start_time}</td>
                        <td>
                            {if condition="$vo.task_end_time eq null"}
                            {else/}
                            {$vo.task_end_time|date="Y-m-d H:i:s",###}
                            {/if}

                        </td>
                        {if condition="$vo.task_status eq 0"}
                        <td>
                            <span class="label label-defaunt radius">待执行</span>
                        </td>
                        {elseif condition="$vo.task_status eq 1"/}
                        <td>
                            <span class="label label-success radius">已完成</span>
                        </td>
                        {else/}
                        {/if}
                        <td>
                            <span class="label label-success radius">
                                {$vo.task_times}
                            </span>
                        </td>
                        <td>{$vo.task_description}</td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="edit_task('编辑任务','{:url(\'task/edit_task\')}?id={$vo.id}','{$vo.id}','950','510')" class="ml-5" style="text-decoration:none">
                                <i class="Hui-iconfont">&#xe6df;</i>
                            </a>&nbsp;
                            <a title="删除" href="javascript:void(0);" style="text-decoration:none" onclick="del_task(this,'{$vo.id}')"><i class="Hui-iconfont Hui-iconfont-del3" title="删除"></i>
                            </a>
                        </td>
                    </tr>
                {/volist}
                </tbody>
            </table>
          </div>
        </div>
    </div>

<!--_footer 作为公共模版分离出去-->
{include file="public/_footer"}


<script type="text/javascript">
    $(function(){
        $('.table-sort').dataTable({
            "aaSorting": [[2,"asc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} ,//控制列的隐藏显示
                {"orderable":false,"aTargets":[0,1,3,4,5,6,7,8,9,10]}// 制定列不参与排序
            ]
        });
    });
</script>

<script>
    //排序ajax提交
    function task_sort(obj){
        var sort = obj.value;
        var task_id = obj.alt;
        $.ajax({
            type:"post",
            url:"{:url('task/task_sort')}",
            data:{sort:sort,id:task_id},
            dataType:"json",
            success:function(msg){
                if(msg.status == true){
                    layer.msg(msg.message,{icon:6,time:1000});
                }else if(msg.status == false){
                    layer.msg(msg.message,{icon:5,time:1000});
                }
            }
        });
    }
    function del_task(obj,id){
        layer.confirm('确定要删除吗',function(index){
            $.ajax({
                type:"post",
                url:"{:url('task/del_task')}",
                data:{id:id},
                dataType:"json",
                success:function(msg){
                    if(msg.status == true){
                        $(obj).parents("tr").remove();
                        layer.msg(msg.message,{icon:6,time:2000});
                        setTimeout(jump,1000);
                        function jump(){
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        }
                    }else if(msg.status == false){
                        layer.msg(msg.message,{icon:5,time:2000});
                    }
                }
            });
        });
    }

    function dataDel(){
        var arr = [];
        var id = $("input[name='id[]']:checked");
        id.each(function(){
            arr.push($(this).val());
        });

        if(arr.length == 0){
            layer.msg('没有选择任何需要删除的！',{icon:5,time:2000});
        }
        $.ajax({
            type : "post",
            url : "{:url('task/batch_del_task')}",
            data : {id:arr},
            dataType : "json",
            success : function(msg){
                if(msg.status == true){
                    layer.msg(msg.message,{icon:6,time:1000});
                    setTimeout(jump,1000);
                    function jump(){
                        window.location.replace(location.href);
                    }
                }else if(msg.status == false){
                    layer.msg(msg.message,{icon:5,time:2000});
                }
            }
        });
    }
    /*新增-任务*/
    function add_task(title,url,id,w,h){
        layer_show(title,url,id,w,h);
    }
    /*修改-任务*/
    function edit_task(title,url,id,w,h){
        layer_show(title,url,w,h);
    }
</script>


